package com.ets.gui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.border.BevelBorder;
import javax.swing.border.Border;
import javax.swing.table.JTableHeader;

public class UserEditPanel extends JPanel 
  {
   private static final long serialVersionUID = 1;	
		
//   private static UserDB          userDAO = null;	
//   private static ArrayList<User> users;
	
   private JButton addButton,
				   changeButton,
				   exitButton;
	
	public UserEditPanel()
	{
		// display panel
		setLayout(new GridBagLayout());
		
		Border loweredBorder
			 = BorderFactory.createBevelBorder(BevelBorder.LOWERED);
		
		JPanel userDisplayPanel = new JPanel();
		
		userDisplayPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
		
//		userDAO = new UserDB();
//		boolean isOK = userDAO.getUsers(users);
		Object[][] tempData = new Object[100][10];
		Object[][] data = tempData;
		String col[] = {"User ID", "First Name", "Middle Name", "Last Name",
				                   "Address", "Phone", "Phone #2", "Email", "Email #2"};
		
		int m = 0;
		
//		for (User aa : users)
//		{
//			System.out.println(aa.getNmFst());
//			tempData[m][0] = aa.getUser();
//			tempData[m][1] = aa.getNmFst();
//			tempData[m][2] = aa.getNmMid();
//			tempData[m][3] = aa.getNmLst();
//			tempData[m][4] = aa.getPhn1();
//			tempData[m][5] = aa.getPhn2();
//			
//			System.out.println(tempData[m][0] + " " + tempData[m][1] + " " + tempData[m][2] + " " + tempData[m][3]);
//			
//			m++;
//		}
				
		JTable table = new JTable(data,col);
		table.getColumnModel().getColumn(1).setPreferredWidth(200); 
		table.getColumnModel().getColumn(2).setPreferredWidth(200); 
		table.getColumnModel().getColumn(3).setPreferredWidth(200); 
		table.getColumnModel().getColumn(4).setPreferredWidth(100); 
		table.getColumnModel().getColumn(5).setPreferredWidth(100); 
		JTableHeader header = table.getTableHeader();
		header.setBackground(Color.yellow);
		table.setBackground(Color.white);
		table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
		
		JScrollPane pane = new JScrollPane(table);
		
		//table.setBackground(getForeground());
		
		pane.setPreferredSize(new Dimension(800, 500)); 
		userDisplayPanel.add(pane);
		
		// button panel
		JPanel buttonPanel = new JPanel();
		buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
		
		//Add button
		addButton = new JButton("Add User");
		buttonPanel.add(addButton);
		addButton.setToolTipText("This is the add button");
		
		//Change button
		changeButton = new JButton("Change User");
		buttonPanel.add(changeButton);
		changeButton.setToolTipText("This is the change button");
		
		//Exit button
		exitButton = new JButton("Exit");
		buttonPanel.add(exitButton);
		exitButton.setToolTipText("This is the exit button");
		
		
		this.add(userDisplayPanel, getConstraints(1,1,3,1, GridBagConstraints.CENTER));
		
		this.add(buttonPanel, getConstraints(1,2,3,1, GridBagConstraints.CENTER));
	}
	
    private void setResizable(boolean b) {
		// TODO Auto-generated method stub
		
	}

	private GridBagConstraints getConstraints(int gridx, int gridy,
    	    int gridwidth, int gridheight, int anchor)
    	    {
    	        GridBagConstraints c = new GridBagConstraints();
    	        c.insets = new Insets(5, 5, 5, 5);
    	        c.ipadx = 5;
    	        c.gridx = gridx;
    	        c.gridy = gridy;
    	        c.gridwidth = gridwidth;
    	        c.gridheight = gridheight;
    	        c.anchor = anchor;
    	        return c;
    	    }

	
	
	
	
	
	
	
	
	
  }
